<?php
/**
 * Created by PhpStorm.
 * Author: sitenv@aliyun.com
 * CreateTime: 2021/07/11 15:50
 * Blog：www.myblogs.xyz
 */

namespace app\common\service;


class LoginService
{
    public static function into()
    {
        $username = input('post.username');
        $password = input('post.password');
        if (empty($username)){
            jsonReturn(1001, '', '请输入登录账户');
        }
        if (empty($password)){
            jsonReturn(1001, '', '请输入账号密码');
        }
        if (is_mobile($username)){
            $where['mobile'] = $username;
        }else{
            $where['account'] = $username;
        }
        $admin_model = new \app\common\model\Admin();
        $admin_data = $admin_model->getFind($where);
        if (empty($admin_data)){
            jsonReturn(1001, '', '该账户不存在');
        }
        if ($admin_data['password'] != $password){
            jsonReturn(1001, '', '您的登录密码有误');
        }
        if ($admin_data['state'] == 1){
            jsonReturn(1001, '', '该账户已锁定');
        }
        if (empty($admin_data['role_id'])){
            jsonReturn(1001, '', '您的没有登录权限');
        }
        $admin_id = $admin_data['admin_id'];
        $login_data['last_time'] = NEW_TIME;
        $login_data['last_ip'] = get_client_ip();
        $admin_model->where('admin_id', $admin_id)->update($login_data);
        cache('admin_id', $admin_id);
        jsonReturn(1000, '', '登录成功');
    }
}